home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2001 November / november_2001.iso / Browsers / Netscape 6.1 / browser.xpi / bin / chrome / comm.jar / content / communicator / openLocation.js < prev    next >
Encoding:
JavaScript  |  2001-04-30  |  4.9 KB  |  154 lines

  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public
  4.  * License Version 1.1 (the "License"); you may not use this file
  5.  * except in compliance with the License. You may obtain a copy of
  6.  * the License at http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the License is distributed on an "AS
  9.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  10.  * implied. See the License for the specific language governing
  11.  * rights and limitations under the License.
  12.  *
  13.  * The Original Code is Mozilla Communicator client code, released March
  14.  * 31, 1998.
  15.  *
  16.  * The Initial Developer of the Original Code is Netscape Communications
  17.  * Corporation. Portions created by Netscape are
  18.  * Copyright (C) 1998 Netscape Communications Corporation. All
  19.  * Rights Reserved.
  20.  *
  21.  * Contributor(s): Michael Lowe <michael.lowe@bigfoot.com>
  22.  *                 Blake Ross   <blakeross@telocity.com>
  23.  */
  24.  
  25. var browser;
  26. var dialog = {};
  27. var pref = null;
  28. try {
  29.   pref = Components.classes["@mozilla.org/preferences;1"]
  30.                    .getService(Components.interfaces.nsIPref);
  31. } catch (ex) {
  32.   // not critical, remain silent
  33. }
  34.  
  35. function onLoad()
  36. {
  37.   dialog.input          = document.getElementById("dialog.input");
  38.   dialog.open           = document.getElementById("ok");
  39.   dialog.openAppList    = document.getElementById("openAppList");
  40.   dialog.openTopWindow  = document.getElementById("currentWindow");
  41.   dialog.openEditWindow = document.getElementById("editWindow");
  42.   dialog.bundle         = document.getElementById("openLocationBundle");
  43.  
  44.   browser = window.arguments[0];
  45.   if (!browser) {
  46.     // No browser supplied - we are calling from Composer
  47.     dialog.openAppList.selectedItem = dialog.openEditWindow;
  48.     dialog.openTopWindow.setAttribute("disabled", "true");
  49.   }
  50.   else {
  51.     dialog.openAppList.selectedItem = dialog.openTopWindow;
  52.   }
  53.  
  54.   // change OK button text to 'open'
  55.   dialog.open.label = dialog.bundle.getString("openButtonLabel");
  56.  
  57.   doSetOKCancel(open, 0, 0, 0);
  58.  
  59.   dialog.input.focus();
  60.   if (pref) {
  61.     try {
  62.       var value = pref.GetIntPref("general.open_location.last_window_choice");
  63.       var element = dialog.openAppList.getElementsByAttribute("value", value)[0];
  64.       if (element)
  65.         dialog.openAppList.selectedItem = element;
  66.       dialog.input.value = pref.CopyUnicharPref("general.open_location.last_url");
  67.     }
  68.     catch(ex) {
  69.     }
  70.     if (dialog.input.value)
  71.       dialog.input.select(); // XXX should probably be done automatically
  72.   }
  73.  
  74.   doEnabling();
  75. }
  76.  
  77. function doEnabling()
  78. {
  79.     dialog.open.disabled = !dialog.input.value;
  80. }
  81.  
  82. function open()
  83. {
  84.   var url;
  85.   if (browser)
  86.     url = browser.getShortcutOrURI(dialog.input.value);
  87.   else
  88.     url = dialog.input.value;
  89.  
  90.   try {
  91.     switch (dialog.openAppList.value) {
  92.       case "0":
  93.         browser.loadURI(url);
  94.         break;
  95.       case "1":
  96.         window.opener.delayedOpenWindow(getBrowserURL(), "all,dialog=no", url);
  97.         break;
  98.       case "2":
  99.         // editPage is in utilityOverlay.js (all editor openers with URL should use this)
  100.         // 3rd param tells editPage to use "delayedOpenWindow"
  101.         editPage(url, window.opener, true);
  102.         break;
  103.     }
  104.   }
  105.   catch(exception) {
  106.   }
  107.  
  108.   if (pref) {
  109.     pref.SetUnicharPref("general.open_location.last_url", dialog.input.value);
  110.     pref.SetIntPref("general.open_location.last_window_choice", dialog.openAppList.value);
  111.   }
  112.  
  113.   // Delay closing slightly to avoid timing bug on Linux.
  114.   window.close();
  115.   return false;
  116. }
  117.  
  118. function createInstance(contractid, iidName)
  119. {
  120.   var iid = Components.interfaces[iidName];
  121.   return Components.classes[contractid].createInstance(iid);
  122. }
  123.  
  124. const nsIFilePicker = Components.interfaces.nsIFilePicker;
  125. function onChooseFile()
  126. {
  127.   try {
  128.     var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
  129.     fp.init(window, dialog.bundle.getString("chooseFileDialogTitle"), nsIFilePicker.modeOpen);
  130.     if (dialog.openAppList.value == "2") {
  131.       // When loading into Composer, direct user to prefer HTML files and text files,
  132.       // so we call separately to control the order of the filter list
  133.       fp.appendFilters(nsIFilePicker.filterHTML | nsIFilePicker.filterText);
  134.       fp.appendFilters(nsIFilePicker.filterText);
  135.       fp.appendFilters(nsIFilePicker.filterAll);
  136.     }
  137.     else {
  138.       fp.appendFilters(nsIFilePicker.filterHTML | nsIFilePicker.filterText |
  139.                        nsIFilePicker.filterAll | nsIFilePicker.filterImages | nsIFilePicker.filterXML);
  140.     }
  141.  
  142.     if (fp.show() == nsIFilePicker.returnOK && fp.fileURL.spec && fp.fileURL.spec.length > 0)
  143.       dialog.input.value = fp.fileURL.spec;
  144.   }
  145.   catch(ex) {
  146.   }
  147.   doEnabling();
  148. }
  149.  
  150. function useUBHistoryItem(aMenuItem)
  151. {
  152.   var urlbar = document.getElementById("dialog.input");
  153.   urlbar.value = aMenuItem.getAttribute("label");
  154. }